<?php
session_start();
include('../includes/config.php');
include('../includes/functions.php');

// 检查用户是否已登录，且是患者角色
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] != 'patient') {
    header("Location: ../login.php");
    exit();
}

// 获取患者ID
$patient_id = $_SESSION['user_id'];

// 获取患者信息
$stmt = $conn->prepare("SELECT u.*, p.* FROM users u JOIN patients p ON u.id = p.user_id WHERE u.id = ?");
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$patient_info = $stmt->get_result()->fetch_assoc();
$stmt->close();

// 检查是否提供了预约ID
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header("Location: appointments.php");
    exit();
}

$appointment_id = $_GET['id'];
$feedback = "";

// 处理取消预约
if (isset($_GET['action']) && $_GET['action'] == 'cancel') {
    // 验证此预约属于当前患者且状态为待确认或已确认
    $check_stmt = $conn->prepare("SELECT id FROM appointments WHERE id = ? AND patient_id = ? AND status IN ('pending', 'confirmed')");
    $check_stmt->bind_param("ii", $appointment_id, $patient_info['id']);
    $check_stmt->execute();
    $check_result = $check_stmt->get_result();
    
    if ($check_result->num_rows > 0) {
        // 更新预约状态为取消
        $update_stmt = $conn->prepare("UPDATE appointments SET status = 'cancelled', updated_at = NOW() WHERE id = ?");
        $update_stmt->bind_param("i", $appointment_id);
        
        if ($update_stmt->execute()) {
            // 添加系统日志
            $log_action = "预约取消";
            $log_description = "患者 {$patient_info['name']} (ID: {$patient_info['id']}) 取消了预约 #$appointment_id";
            $log_stmt = $conn->prepare("INSERT INTO system_logs (action, description, user_id, user_role, created_at) VALUES (?, ?, ?, ?, NOW())");
            $log_stmt->bind_param("ssis", $log_action, $log_description, $patient_id, $_SESSION['user_role']);
            $log_stmt->execute();
            $log_stmt->close();
            
            $feedback = '<div class="alert alert-success">预约已成功取消</div>';
        } else {
            $feedback = '<div class="alert alert-danger">取消预约失败，请稍后重试</div>';
        }
        $update_stmt->close();
    } else {
        $feedback = '<div class="alert alert-danger">无效的操作或预约已不可取消</div>';
    }
    $check_stmt->close();
}

// 获取预约详情
$query = "
    SELECT a.*, d.title, d.specialty, u.name as doctor_name, u.email as doctor_email, 
           u.phone as doctor_phone, dp.name as department_name, dp.location 
    FROM appointments a 
    JOIN doctors d ON a.doctor_id = d.id 
    JOIN users u ON d.user_id = u.id 
    JOIN departments dp ON a.department_id = dp.id 
    WHERE a.id = ? AND a.patient_id = ?
";

$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $appointment_id, $patient_info['id']);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows == 0) {
    // 预约不存在或不属于当前患者
    header("Location: appointments.php");
    exit();
}

$appointment = $result->fetch_assoc();
$stmt->close();

// 检查是否有相关的医疗记录
$med_record_query = "SELECT * FROM medical_records WHERE appointment_id = ?";
$med_stmt = $conn->prepare($med_record_query);
$med_stmt->bind_param("i", $appointment_id);
$med_stmt->execute();
$med_result = $med_stmt->get_result();
$has_medical_record = ($med_result->num_rows > 0);
$medical_record = $has_medical_record ? $med_result->fetch_assoc() : null;
$med_stmt->close();

// 检查是否有相关的处方
$prescription_query = "
    SELECT p.*, u.name as doctor_name 
    FROM prescriptions p 
    JOIN doctors d ON p.doctor_id = d.id 
    JOIN users u ON d.user_id = u.id 
    WHERE p.appointment_id = ?
";
$pres_stmt = $conn->prepare($prescription_query);
$pres_stmt->bind_param("i", $appointment_id);
$pres_stmt->execute();
$pres_result = $pres_stmt->get_result();
$has_prescription = ($pres_result->num_rows > 0);
$prescription = $has_prescription ? $pres_result->fetch_assoc() : null;
$pres_stmt->close();

// 如果有处方，获取处方药品
$prescription_medicines = [];
if ($has_prescription) {
    $pm_query = "
        SELECT pm.*, m.name, m.description, m.unit, m.category 
        FROM prescription_medicines pm 
        JOIN medicines m ON pm.medicine_id = m.id 
        WHERE pm.prescription_id = ?
    ";
    $pm_stmt = $conn->prepare($pm_query);
    $pm_stmt->bind_param("i", $prescription['id']);
    $pm_stmt->execute();
    $pm_result = $pm_stmt->get_result();
    while ($row = $pm_result->fetch_assoc()) {
        $prescription_medicines[] = $row;
    }
    $pm_stmt->close();
}

// 检查是否有相关的账单
$bill_query = "SELECT * FROM bills WHERE appointment_id = ?";
$bill_stmt = $conn->prepare($bill_query);
$bill_stmt->bind_param("i", $appointment_id);
$bill_stmt->execute();
$bill_result = $bill_stmt->get_result();
$has_bill = ($bill_result->num_rows > 0);
$bill = $has_bill ? $bill_result->fetch_assoc() : null;
$bill_stmt->close();
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约详情 - 医院信息系统</title>
    <link rel="stylesheet" href="/assets\css/bootstrap_69c9e605.min.css">
    <link rel="stylesheet" href="/assets\css/style.css">
    <link rel="stylesheet" href="/assets\css/all_de197510.min.css">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
                <div class="position-sticky pt-3">
                    <div class="text-center mb-4">
                        <img src="../assets/images/patient-avatar.png" alt="患者头像" class="img-fluid rounded-circle mx-auto d-block" style="width: 80px;">
                        <h5 class="mt-2"><?php echo htmlspecialchars($patient_info['name']); ?></h5>
                        <p class="text-muted">患者ID: <?php echo htmlspecialchars($patient_info['id']); ?></p>
                    </div>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="index.php">
                                <i class="fas fa-home"></i> 个人中心
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="appointments.php">
                                <i class="fas fa-calendar-check"></i> 我的预约
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="book_appointment.php">
                                <i class="fas fa-plus-circle"></i> 预约挂号
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="medical_records.php">
                                <i class="fas fa-notes-medical"></i> 病历记录
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="prescriptions.php">
                                <i class="fas fa-prescription"></i> 处方信息
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="bills.php">
                                <i class="fas fa-file-invoice-dollar"></i> 账单管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="profile.php">
                                <i class="fas fa-user"></i> 个人信息
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="../logout.php">
                                <i class="fas fa-sign-out-alt"></i> 退出登录
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">预约详情</h1>
                    <div class="btn-toolbar mb-2 mb-md-0">
                        <a href="appointments.php" class="btn btn-sm btn-outline-secondary">
                            <i class="fas fa-arrow-left"></i> 返回列表
                        </a>
                    </div>
                </div>

                <?php echo $feedback; ?>

                <!-- 预约状态卡片 -->
                <div class="row mb-4">
                    <div class="col-md-12">
                        <div class="card border-0 shadow-sm">
                            <div class="card-body d-flex align-items-center">
                                <div class="appointment-status-icon me-3">
                                    <?php
                                    switch ($appointment['status']) {
                                        case 'pending':
                                            echo '<span class="status-circle bg-warning"><i class="fas fa-clock"></i></span>';
                                            break;
                                        case 'confirmed':
                                            echo '<span class="status-circle bg-info"><i class="fas fa-check"></i></span>';
                                            break;
                                        case 'completed':
                                            echo '<span class="status-circle bg-success"><i class="fas fa-check-double"></i></span>';
                                            break;
                                        case 'cancelled':
                                            echo '<span class="status-circle bg-danger"><i class="fas fa-times"></i></span>';
                                            break;
                                        default:
                                            echo '<span class="status-circle bg-secondary"><i class="fas fa-question"></i></span>';
                                    }
                                    ?>
                                </div>
                                <div>
                                    <h4 class="card-title mb-1">预约状态：
                                        <?php
                                        switch ($appointment['status']) {
                                            case 'pending':
                                                echo '<span class="badge bg-warning">待确认</span>';
                                                break;
                                            case 'confirmed':
                                                echo '<span class="badge bg-info">已确认</span>';
                                                break;
                                            case 'completed':
                                                echo '<span class="badge bg-success">已完成</span>';
                                                break;
                                            case 'cancelled':
                                                echo '<span class="badge bg-danger">已取消</span>';
                                                break;
                                            default:
                                                echo '<span class="badge bg-secondary">未知</span>';
                                        }
                                        ?>
                                    </h4>
                                    <p class="card-text text-muted mb-0">预约编号: #<?php echo $appointment['id']; ?> | 创建时间: <?php echo date('Y-m-d H:i', strtotime($appointment['created_at'])); ?></p>
                                </div>
                                <div class="ms-auto">
                                    <?php if ($appointment['status'] == 'pending' || $appointment['status'] == 'confirmed'): ?>
                                        <a href="appointment_details.php?id=<?php echo $appointment['id']; ?>&action=cancel" class="btn btn-danger" onclick="return confirm('确定要取消此预约吗？此操作不可撤销。')">
                                            <i class="fas fa-times"></i> 取消预约
                                        </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <!-- 预约信息 -->
                    <div class="col-md-8">
                        <div class="card shadow-sm mb-4">
                            <div class="card-header py-3">
                                <h5 class="mb-0"><i class="fas fa-info-circle"></i> 基本信息</h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-4">
                                    <div class="col-md-6">
                                        <h6 class="fw-bold mb-3 text-secondary"><i class="fas fa-calendar-alt"></i> 预约时间</h6>
                                        <div class="d-flex align-items-center mb-2">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-calendar-day"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">日期</div>
                                                <div class="fw-bold"><?php echo date('Y年m月d日', strtotime($appointment['appointment_date'])); ?></div>
                                            </div>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-clock"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">时间段</div>
                                                <div class="fw-bold"><?php echo $appointment['appointment_time']; ?></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <h6 class="fw-bold mb-3 text-secondary"><i class="fas fa-stethoscope"></i> 预约科室</h6>
                                        <div class="d-flex align-items-center mb-2">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-hospital"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">科室</div>
                                                <div class="fw-bold"><?php echo htmlspecialchars($appointment['department_name']); ?></div>
                                            </div>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-map-marker-alt"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">位置</div>
                                                <div class="fw-bold"><?php echo htmlspecialchars($appointment['location']); ?></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <hr>

                                <div class="row mb-4">
                                    <div class="col-md-6">
                                        <h6 class="fw-bold mb-3 text-secondary"><i class="fas fa-user-md"></i> 医生信息</h6>
                                        <div class="d-flex align-items-center mb-2">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-user-md"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">姓名</div>
                                                <div class="fw-bold"><?php echo htmlspecialchars($appointment['doctor_name']); ?></div>
                                            </div>
                                        </div>
                                        <div class="d-flex align-items-center mb-2">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-tag"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">职称</div>
                                                <div class="fw-bold"><?php echo htmlspecialchars($appointment['title']); ?></div>
                                            </div>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <div class="icon-box me-2 bg-light text-primary">
                                                <i class="fas fa-briefcase-medical"></i>
                                            </div>
                                            <div>
                                                <div class="small text-muted">专长</div>
                                                <div class="fw-bold"><?php echo htmlspecialchars($appointment['specialty']); ?></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <h6 class="fw-bold mb-3 text-secondary"><i class="fas fa-comment-medical"></i> 预约原因</h6>
                                        <div class="card bg-light">
                                            <div class="card-body py-2">
                                                <?php echo nl2br(htmlspecialchars($appointment['reason'])); ?>
                                            </div>
                                        </div>
                                        <?php if (!empty($appointment['notes'])): ?>
                                            <h6 class="fw-bold mb-2 mt-3 text-secondary"><i class="fas fa-sticky-note"></i> 备注</h6>
                                            <div class="card bg-light">
                                                <div class="card-body py-2">
                                                    <?php echo nl2br(htmlspecialchars($appointment['notes'])); ?>
                                                </div>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 医疗记录 -->
                        <?php if ($has_medical_record): ?>
                        <div class="card shadow-sm mb-4">
                            <div class="card-header py-3">
                                <h5 class="mb-0"><i class="fas fa-notes-medical"></i> 就诊记录</h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <div class="small text-muted">就诊时间</div>
                                        <div class="h6"><?php echo date('Y-m-d H:i', strtotime($medical_record['created_at'])); ?></div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="small text-muted">医生</div>
                                        <div class="h6"><?php echo htmlspecialchars($appointment['doctor_name']); ?></div>
                                    </div>
                                </div>
                                
                                <div class="mb-3">
                                    <div class="small text-muted">症状描述</div>
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <?php echo nl2br(htmlspecialchars($medical_record['symptoms'])); ?>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="mb-3">
                                    <div class="small text-muted">诊断结果</div>
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <?php echo nl2br(htmlspecialchars($medical_record['diagnosis'])); ?>
                                        </div>
                                    </div>
                                </div>
                                
                                <?php if (!empty($medical_record['treatment_plan'])): ?>
                                <div class="mb-3">
                                    <div class="small text-muted">治疗方案</div>
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <?php echo nl2br(htmlspecialchars($medical_record['treatment_plan'])); ?>
                                        </div>
                                    </div>
                                </div>
                                <?php endif; ?>
                                
                                <?php if (!empty($medical_record['notes'])): ?>
                                <div>
                                    <div class="small text-muted">医生备注</div>
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <?php echo nl2br(htmlspecialchars($medical_record['notes'])); ?>
                                        </div>
                                    </div>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endif; ?>

                        <!-- 处方信息 -->
                        <?php if ($has_prescription): ?>
                        <div class="card shadow-sm mb-4">
                            <div class="card-header py-3">
                                <h5 class="mb-0"><i class="fas fa-prescription"></i> 处方信息</h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-3">
                                    <div class="col-md-4">
                                        <div class="small text-muted">处方编号</div>
                                        <div class="h6">#<?php echo $prescription['id']; ?></div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="small text-muted">开具时间</div>
                                        <div class="h6"><?php echo date('Y-m-d', strtotime($prescription['created_at'])); ?></div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="small text-muted">状态</div>
                                        <div class="h6">
                                            <?php
                                            switch ($prescription['status']) {
                                                case 'active':
                                                    echo '<span class="badge bg-success">有效</span>';
                                                    break;
                                                case 'filled':
                                                    echo '<span class="badge bg-info">已配药</span>';
                                                    break;
                                                case 'expired':
                                                    echo '<span class="badge bg-warning">已过期</span>';
                                                    break;
                                                default:
                                                    echo '<span class="badge bg-secondary">未知</span>';
                                            }
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                
                                <?php if (!empty($prescription['notes'])): ?>
                                <div class="mb-3">
                                    <div class="small text-muted">医嘱</div>
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <?php echo nl2br(htmlspecialchars($prescription['notes'])); ?>
                                        </div>
                                    </div>
                                </div>
                                <?php endif; ?>
                                
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover">
                                        <thead class="table-light">
                                            <tr>
                                                <th>药品名称</th>
                                                <th>规格</th>
                                                <th>用量</th>
                                                <th>用法</th>
                                                <th>数量</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($prescription_medicines as $medicine): ?>
                                            <tr>
                                                <td><?php echo htmlspecialchars($medicine['name']); ?></td>
                                                <td><?php echo htmlspecialchars($medicine['unit']); ?></td>
                                                <td><?php echo htmlspecialchars($medicine['dosage']); ?></td>
                                                <td><?php echo htmlspecialchars($medicine['instructions']); ?></td>
                                                <td><?php echo htmlspecialchars($medicine['quantity']); ?></td>
                                            </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                                
                                <div class="alert alert-info mt-3">
                                    <i class="fas fa-info-circle"></i> 请凭处方和就诊卡到药房取药。处方有效期为7天。
                                </div>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                    
                    <!-- 侧边信息 -->
                    <div class="col-md-4">
                        <!-- 账单信息 -->
                        <?php if ($has_bill): ?>
                        <div class="card shadow-sm mb-4">
                            <div class="card-header py-3">
                                <h5 class="mb-0"><i class="fas fa-file-invoice-dollar"></i> 账单信息</h5>
                            </div>
                            <div class="card-body">
                                <div class="d-flex justify-content-between mb-2">
                                    <span>账单编号:</span>
                                    <span class="fw-bold">#<?php echo $bill['id']; ?></span>
                                </div>
                                <div class="d-flex justify-content-between mb-2">
                                    <span>金额:</span>
                                    <span class="fw-bold">¥<?php echo number_format($bill['amount'], 2); ?></span>
                                </div>
                                <div class="d-flex justify-content-between mb-2">
                                    <span>状态:</span>
                                    <span>
                                        <?php
                                        switch ($bill['status']) {
                                            case 'pending':
                                                echo '<span class="badge bg-warning">待支付</span>';
                                                break;
                                            case 'paid':
                                                echo '<span class="badge bg-success">已支付</span>';
                                                break;
                                            case 'cancelled':
                                                echo '<span class="badge bg-danger">已取消</span>';
                                                break;
                                            default:
                                                echo '<span class="badge bg-secondary">未知</span>';
                                        }
                                        ?>
                                    </span>
                                </div>
                                <div class="d-flex justify-content-between mb-2">
                                    <span>创建时间:</span>
                                    <span><?php echo date('Y-m-d', strtotime($bill['created_at'])); ?></span>
                                </div>
                                <?php if ($bill['status'] == 'paid'): ?>
                                <div class="d-flex justify-content-between">
                                    <span>支付时间:</span>
                                    <span><?php echo date('Y-m-d', strtotime($bill['paid_at'])); ?></span>
                                </div>
                                <?php endif; ?>
                                
                                <?php if ($bill['status'] == 'pending'): ?>
                                <div class="d-grid gap-2 mt-3">
                                    <a href="pay_bill.php?id=<?php echo $bill['id']; ?>" class="btn btn-primary">
                                        <i class="fas fa-credit-card"></i> 立即支付
                                    </a>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <!-- 就诊须知 -->
                        <?php if ($appointment['status'] == 'confirmed'): ?>
                        <div class="card shadow-sm mb-4 border-info">
                            <div class="card-header bg-info text-white py-3">
                                <h5 class="mb-0"><i class="fas fa-info-circle"></i> 就诊须知</h5>
                            </div>
                            <div class="card-body">
                                <ul class="list-group list-group-flush">
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-check-circle text-success me-2 mt-1"></i>
                                        <div>请提前15分钟到达医院，携带身份证和医保卡</div>
                                    </li>
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-check-circle text-success me-2 mt-1"></i>
                                        <div>位置：<?php echo htmlspecialchars($appointment['location']); ?></div>
                                    </li>
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-check-circle text-success me-2 mt-1"></i>
                                        <div>请保持手机畅通，如需取消请提前24小时操作</div>
                                    </li>
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-check-circle text-success me-2 mt-1"></i>
                                        <div>如有不适，请提前准备好相关检查资料</div>
                                    </li>
                                </ul>
                                
                                <div class="alert alert-warning mt-3 mb-0">
                                    <i class="fas fa-exclamation-triangle"></i> 如需取消，请至少提前24小时操作，否则可能影响您的就诊信用记录。
                                </div>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <!-- 联系方式 -->
                        <div class="card shadow-sm mb-4">
                            <div class="card-header py-3">
                                <h5 class="mb-0"><i class="fas fa-address-card"></i> 联系方式</h5>
                            </div>
                            <div class="card-body">
                                <h6 class="card-title">科室联系方式</h6>
                                <p class="card-text">如有问题，可通过以下方式联系科室</p>
                                <ul class="list-group list-group-flush mb-3">
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-phone-alt text-primary me-2 mt-1"></i>
                                        <div>电话：<?php echo rand(100, 999) . '-' . rand(1000, 9999) . '-' . rand(1000, 9999); ?></div>
                                    </li>
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-envelope text-primary me-2 mt-1"></i>
                                        <div>邮箱：<?php echo strtolower(str_replace(' ', '', $appointment['department_name'])) . '@hospital.com'; ?></div>
                                    </li>
                                </ul>
                                
                                <h6 class="card-title">医生联系方式</h6>
                                <ul class="list-group list-group-flush">
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-phone-alt text-primary me-2 mt-1"></i>
                                        <div>电话：<?php echo !empty($appointment['doctor_phone']) ? $appointment['doctor_phone'] : '暂无'; ?></div>
                                    </li>
                                    <li class="list-group-item d-flex">
                                        <i class="fas fa-envelope text-primary me-2 mt-1"></i>
                                        <div>邮箱：<?php echo !empty($appointment['doctor_email']) ? $appointment['doctor_email'] : '暂无'; ?></div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <!-- 脚本 -->
    <script src="/assets\js/jquery-3.6.0.min.js"></script></script></script>
    <script src="/assets\js/bootstrap.bundle.min.js"></script></script></script>
    <style>
        .icon-box {
            width: 40px;
            height: 40px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .status-circle {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
        }
    </style>
</body>
</html> 